package coolq.yaozhenyong.controller;

import com.forte.qqrobot.anno.Filter;
import com.forte.qqrobot.anno.Listen;
import com.forte.qqrobot.anno.depend.Beans;
import com.forte.qqrobot.beans.messages.msgget.FriendAddRequest;
import com.forte.qqrobot.beans.messages.msgget.GroupAddRequest;
import com.forte.qqrobot.beans.messages.result.GroupInfo;
import com.forte.qqrobot.beans.messages.types.GroupAddRequestType;
import com.forte.qqrobot.beans.messages.types.MsgGetTypes;
import com.forte.qqrobot.sender.MsgSender;

import coolq.yaozhenyong.bean.GroupList;
import coolq.yaozhenyong.custom.SpringContextUtil;
import coolq.yaozhenyong.custom.TimeUtils;
import coolq.yaozhenyong.service.GroupListService;

@Beans
public class MyGroupAddRequestController {
	/****
	 *	请求-群添加
	 */
	@Listen(MsgGetTypes.groupAddRequest)
	@Filter
	public void groupAddRequest(GroupAddRequest msg,MsgSender sender,GroupAddRequestType requestType) {//	群添加请求事件
		GroupListService bean = SpringContextUtil.getBean(GroupListService.class);
		GroupList one = bean.query().eq("groupcode", msg.getGroup()).eq("isfalsetrue", "在群").one();
		if(one==null) {
			try {
				GroupInfo groupInfo = sender.GETTER.getGroupInfo(msg.getGroup());
				String[] adminList = groupInfo.getAdminList();
				String adminLists = "● 管理员";
				for (int i = 0; i < adminList.length; i++) {
					adminLists += adminList[i]+"|";
				}
				sender.SENDER.sendPrivateMsg("936642284",adminLists
						+"\n"+groupInfo.getCompleteIntro()
						+ "\n● QQ群"+msg.getGroup()
						+ "\n● 群名称"+groupInfo.getName()
						+ "\n● 群人数"+groupInfo.getMemberNum()
						+ "\n● 上限人数" +groupInfo.getMaxMember());
			} catch (Exception e) {
				
			}
			sender.SENDER.sendPrivateMsg("936642284","复制我同意群邀请["+msg.getFlag()+"]");
		}
	}
	
	/****
	 *请求-添加好友
	 */
	@Listen(MsgGetTypes.friendAddRequest)
	@Filter
	public void friendAddRequest(FriendAddRequest msg,MsgSender sender) {//	好友添加申请事件
		System.out.println(msg.getQQ()+"请求-添加好友");
		try {
			sender.SETTER.setFriendAddRequest(msg.getFlag(), TimeUtils.getStringDate()+"0",true);
		}catch (Exception e) {
			sender.SENDER.sendPrivateMsg("936642284", msg.getQQ()+"已添加为好友！发送错误" + msg.getFlag());
		}
		sender.SENDER.sendPrivateMsg("936642284", msg.getQQ()+"已添加为好友！" + msg.getFlag());
		sender.SENDER.sendPrivateMsg(msg.getQQ(), "您好，机器人小熙为你服务，机器人各种功能请前往我的空间查看哦！\r\n我主要是针对QQ群协助"
				+ "管理的机器人哦，后台为网页操作，不会冲浪的小伙伴请止步！"
				+ "\n我的主人也在努力的丰富我的各种功能，希望能把自己最好的一面呈现给大家！"
				+ "893778789欢迎加入我们的机器人体验群聊！有什么问题，优化，bug欢迎反馈！"
				+ "以后申请机器人必须添加此QQ群893778789，因为暂时用户量比较多，需要进行截流，大家进群体验机器人后，根据需求是否需要在申请！");
	}
}
